package com.elastic.search;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.index.query.FilterBuilders.*;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
public class QueryDsl {
 
	/**
	 * QueryBuilder可以用于任何API接受查询,如计数和搜索。
	 */
	public static void testMatchQuery(){
		QueryBuilder qb = matchQuery(
			    "name",                  
			    "xiaocai"   
			);
	}
	
	/**
	 * 
	 * 1   个参数是值
	 * 2 个参数是需要查询的字段都满足这个值的 fields
	 * 
	 * user,age == kimchy elasticsearch
	 */
	public static void testMultiFiledQuery(){
		QueryBuilder qb = multiMatchQuery(
			    "kimchy elasticsearch", 
			    "user", "age"       
			);
	}
	
	/**
	 * 混合另外还有混合查询如 bool 等.
	 * 必须满足 Must mustNot, should
	 * 
	 * and 1- 2 and ds !=dsd or 1-3
	 * 
	 */
	public static void testQoolQuery(){
		QueryBuilder qb = boolQuery()
			    .must(termQuery("content", "test1"))    
			    .must(termQuery("content", "test4"))    
			    .mustNot(termQuery("content", "test2")) 
			    .should(termQuery("content", "test3")); 
		//QueryBuilders.queryString("预定").defaultField("tradeStatus")
	}
	
	public static void testBoostingQuery(){
		QueryBuilder qb = boostingQuery()
			    .positive(termQuery("name","kimchy"))   
			    .negative(termQuery("name","dadoonet")) 
			    .negativeBoost(0.2f);  
	}
	
	//文档ids, 不是对象的Id
    public static void testIdsQuery(){
    	QueryBuilder qb = idsQuery().ids("1", "2"); 
    }
	
    /**
     * filter 能向 query 转 的过程
     * 
     */
    public static void testBoostf(){
    	//QueryBuilders.constantScoreQuery()
    	QueryBuilder qb = constantScoreQuery(
    			termFilter("name","kimchy")     
    	    )
    	    .boost(2.0f);  
    	
    	QueryBuilder qb2 = constantScoreQuery(
    	        termQuery("name","kimchy")      
    	    )
    	    .boost(2.0f);                       
    }
	
    private static void likequery(){
    	QueryBuilder qb = fuzzyLikeThisQuery("name.first", "name.last") 
    		    .likeText("text like this one")                             
    		    .maxQueryTerms(12); 
    	
    	QueryBuilder qb23 = fuzzyLikeThisFieldQuery("name.first")         
                .likeText("text like this one")                 
                .maxQueryTerms(12);                         
    }
    
    QueryBuilder qb4 = fuzzyQuery(
    	    "name",     
    	    "kimzhy"    
    	);
}
